import { TaskInfo } from "../../../model/TaskInfo";
import { ETaskStatus } from "../../../../../Message/Game/ETaskStatus";
import { EReward } from "../../../../../Message/Public/EReward";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { Language } from "../../../../../extend/language/Language";
import { LGXBTaskItem } from "./LGXBTaskItem";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { PageSelectCenter } from "../../common/pageSelect/PageSelectCenter";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class LGXBDescRightWin
    
    export  class LGXBDescRightWin /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            return;
        }

        public updateWin(arg1: Boolean, arg2: TaskInfo, arg3: string, arg4: string): void
        {
            var loc1=false;
            if (arg1) 
            {
                this._taskInfo = arg2;
                loc1 = this.updataTaskView(arg2);
                if (this.checkboxIsSelected && loc1) 
                {
                    this._taskInfo = null;
                    this.updateDesc(arg4, arg3);
                    this.showDesc();
                }
                else 
                {
                    if (this._taskItem.hasClickQuickBtn) 
                    {
                        this._taskItem.clickGetBonusHandler();
                        this._taskInfo = null;
                        this.updateDesc(arg4, arg3);
                        this.showDesc();
                    }
                    else 
                    {
                        this.showTask();
                    }
                    this._taskItem.hasClickQuickBtn = false;
                }
                if (arg2.status == ETaskStatus._ETaskStatusNotCompleted || arg2.status == ETaskStatus._ETaskStatusHadCompleted) 
                {
                    this.showTask();
                }
                else 
                {
                    this.updateDesc(arg4, arg3);
                    this.showDesc();
                }
            }
            else 
            {
                this._taskInfo = null;
                this.updateDesc(arg4, arg3);
                this.showDesc();
            }
            return;
        }

        /* internal  */showTask(): void
        {
            if (this._taskSp && this._taskSp.parent == null) 
            {
                this.addChild(this._taskSp);
            }
            if (this._descSp && !(this._descSp.parent == null)) 
            {
                this.removeChild(this._descSp);
            }
            return;
        }

        /* internal  */showDesc(): void
        {
            if (this._descSp && this._descSp.parent == null) 
            {
                this.addChild(this._descSp);
            }
            if (this._taskSp && !(this._taskSp.parent == null)) 
            {
                this.removeChild(this._taskSp);
            }
            return;
        }

        /* internal  */updateDesc(arg1: string, arg2: string): void
        {
            if (this._descSp == null) 
            {
                this.initDesc();
            }
            this._txtTitle.htmlText = arg1;
            this._txtDesc.htmlText = arg2;
            return;
        }

        /* internal  */updataTaskView(arg1: TaskInfo): Boolean
        {
            var loc6=null;
            if (this._taskSp == null) 
            {
                this.initTask();
            }
            this._taskItem.updateData(arg1);
            var loc1=arg1.sTask.rewards;
            var loc2=0;
            var loc3=0;
            var loc4=0;
            var loc5=[];
            var loc7=0;
            var loc8=loc1;
            for(loc6 of loc8) 
            {
                if (loc6.type == EReward._ERewardExperience) 
                {
                    loc3 = loc6.num;
                    continue;
                }
                if (loc6.type == EReward._ERewardCoinBind || loc6.type == EReward._ERewardCoin) 
                {
                    loc2 = loc6.num;
                    continue;
                }
                if (loc6.type == EReward._ERewardItem) 
                {
                    loc5.push(loc6.code);
                    continue;
                }
                if (loc6.type != EReward._ERewardNimbus) 
                {
                    continue;
                }
                loc4 = loc6.num;
            }
            this._txtTaskName.htmlText = arg1.taskName;
            this._txtCoin.text = loc2.toString();
            this._txtExperience.text = loc3.toString();
            this._txtLingQi.text = loc4.toString();
            return this.checkQuickComplete();
        }

        public checkQuickComplete(): Boolean
        {
            if (!this._taskInfo) 
            {
                return false;
            }
            var loc1=true;
            if (this._taskInfo.status != ETaskStatus._ETaskStatusHadCompleted) 
            {
                this._taskItem.updateBtnLabel(true);
                if (this.checkboxIsSelected) 
                {
                    loc1 = this._taskItem.quickCompleteHander();
                }
            }
            else 
            {
                this._taskItem.updateBtnLabel(false);
                if (this.checkboxIsSelected) 
                {
                    this._taskItem.clickGetBonusHandler();
                }
            }
            return loc1;
        }

        /* internal  */initDesc(): void
        {
            this._descSp = new Object /* flash.display.Sprite */();
            this.addChild(this._descSp);
            this._txtTitle = ObjCreate.createGTextField("", 0, 12, 185, 20, this._descSp);
            var loc1=this._txtTitle.defaultTextFormat;
            loc1.align = flash.text.TextFormatAlign.CENTER;
            loc1.size = 16;
            loc1.bold = true;
            loc1.color = 16776960;
            this._txtTitle.defaultTextFormat = loc1;
            this._txtDesc = ObjCreate.createGTextField("", 5, 50, 180, 430, this._descSp);
            this._txtDesc.multiline = true;
            this._txtDesc.wordWrap = true;
            loc1 = this._txtDesc.defaultTextFormat;
            loc1.leading = 5;
            this._txtDesc.defaultTextFormat = loc1;
            return;
        }

        /* internal  */initTask(): void
        {
            this._taskSp = new Object /* flash.display.Sprite */();
            ObjCreate.createBitmap(ImagesConst.fairylandPattern, 0, 4, this._taskSp);
            var loc1=ObjCreate.createGTextField("", 8, 6, 220, 20, this._taskSp);
            var loc2=loc1.defaultTextFormat;
            loc2.size = 17;
            loc2.color = 16776960;
            loc1.defaultTextFormat = loc2;
            loc1.text = Language.getString(35010);
            this._txtTaskName = ObjCreate.createGTextField("", 8, 40, 200, 20, this._taskSp);
            this._taskItem = new LGXBTaskItem();
            this._taskItem.x = 8;
            this._taskItem.y = 60;
            this._taskSp.addChild(this._taskItem);
            ObjCreate.createBg(0, 144, 185, 1, this._taskSp, ImagesConst.SplitLine);
            ObjCreate.createBitmap(ImagesConst.fairylandPattern, 0, 146, this._taskSp);
            ObjCreate.createBitmap(ImagesConst.LGXB_reward, 6, 153, this._taskSp);
            loc1 = this.getRedFilterText(this._taskSp);
            loc1.x = 8;
            loc1.y = 185;
            loc1.text = Language.getString(40085);
            loc2 = GlobalStyle.textFormat9;
            this._txtCoin = ObjCreate.createGTextField("", 40, 185, 200, 20, this._taskSp, loc2);
            loc1 = this.getRedFilterText(this._taskSp);
            loc1.x = 8;
            loc1.y = 218;
            loc1.text = Language.getString(80283);
            this._txtExperience = ObjCreate.createGTextField("", 40, 218, 200, 20, this._taskSp, loc2);
            loc1 = this.getRedFilterText(this._taskSp);
            loc1.x = 8;
            loc1.y = 250;
            loc1.text = Language.getString(11011);
            this._txtLingQi = ObjCreate.createGTextField("", 40, 250, 200, 20, this._taskSp, loc2);
            ObjCreate.createBg(0, 398, 185, 1, this._taskSp, ImagesConst.SplitLine);
            return;
        }

        /* internal  */getRedFilterText(arg1: Object /* flash.display.DisplayObjectContainer */): GTextFiled
        {
            var loc1=GlobalStyle.textFormatOrange;
            loc1.size = 13;
            var loc2=ObjCreate.createGTextField("", 0, 0, 200, 20, arg1, loc1);
            return loc2;
        }

        /* internal  */initView(): void
        {
            ObjCreate.createBg(0, 0, 185, 480, this);
            return;
        }

        /* internal */ /* var */_taskSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_txtTaskName: GTextFiled;

        /* internal */ /* var */_taskItem: LGXBTaskItem;

        /* internal */ /* var */_txtCoin: GTextFiled;

        /* internal */ /* var */_txtExperience: GTextFiled;

        /* internal */ /* var */_txtJilv: GTextFiled;

        /* internal */ /* var */_txtLingQi: GTextFiled;

        /* internal */ /* var */_rewerds: PageSelectCenter;

        /* internal */ /* var */_btnGet: GButton;

        /* internal */ /* var */_taskInfo: TaskInfo;

        /* internal */ /* var */_descSp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_txtTitle: GTextFiled;

        /* internal */ /* var */_txtDesc: GTextFiled;

        public /* var */checkboxIsSelected: Boolean=false;
    }
